package com.liner.string;

public class StringDemo {
    public static void main(String[] args) {
        /*
         * 字符串常量池
         *
         * 使用字面量 “ ”  直接创建的字符串对象，JVM检查常量池是否有对象，
         * 没有则创建字符串对象，并将其引入常量池中
         * 有 则直接从常量池中的对象 引用返回，并不需要创建性的字符串对象
         *
         */

        String s1 = "hello";
        s1 = s1 + "!";

        s1 = "hello!";
        String s2 = "hello" + "!";
        System.out.println(s1 == s2);

        Object o = new Object();


        String s3 = new String("hello");
        String s4 = new String("hello");


        String s7 = new String("hello");

        String s8 = "hello";
        System.out.println(s8 == s7);   //false
        System.out.println(s8 .equals(s7) );   //true

        String s9 = s7.intern();
        System.out.println(s9 == s7); //false
        System.out.println(s9 == s8); //true

        System.out.println(s1 == s2);
        System.out.println(s2 == s3);
        System.out.println(s3 == s4);
        System.out.println(s1.equals(s2));
        System.out.println(s2.equals(s3));
        System.out.println(s3.equals(s4));


    }

}
